package com.gzmu.face.serviceImpl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.gzmu.face.entity.User;
import com.gzmu.face.entity.UserRole;
import com.gzmu.face.mapper.UserMapper;
import com.gzmu.face.service.UserRoleService;
import com.gzmu.face.service.UserService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaobo Yan
 * @since 2020-04-19
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserRoleService userRoleService;

    @Transactional
    @Override
    public int insertOperator(User user, int role) {
        userMapper.insertUser( user );
        UserRole userRole = new UserRole();
        userRole.setUserid( user.getId() );
        userRole.setRoleid( role );
        userRoleService.insert(userRole);
        return 200;
    }

    @Transactional
    @Override
    public int deleteOperator(String id) {
        userMapper.deleteById( id );
        userRoleService.delete( new EntityWrapper<UserRole>(  ).eq( "user_id", id) );
        return 200;
    }
}
